/*memset 以字节为单位进行初始化*/
#include<bits/stdc++.h>

#define YES 1
#define NO -1

#define GraphDepth 20
#define GraphWidth 20
#define rp(i,n) for(int i=0;i<n;i++)

using namespace std;

int isOk(int left,int bottom,int a[GraphDepth][GraphWidth], int b[5][5]){
	for(int j=bottom;j >= bottom - 3;--j){
		for(int i = left; i<=left+3;++i){
			// printf("j = %d, i = %d, a[j][i] = %d, b[4 - (bottom - j)][i-left+1]= %d\n",j,i,a[j][i],b[4 - (bottom - j)][i-left+1]);
			if(a[j][i] == 1 && b[4 - (bottom - j)][i-left+1] == 1){
				return NO;
			}
		}
	}
	return YES;
}

void merge(int a[GraphDepth][GraphWidth], int b[5][5], int modelLeft){
	int bottomLevel = 5;
	while(1){
		if(isOk(modelLeft,bottomLevel,a,b) == NO){
			break;
		}
		++bottomLevel;
	}
	--bottomLevel;
	// printf("bottom = %d\n", bottomLevel);
	for(int j=bottomLevel;j >= bottomLevel - 3;--j){
		for(int i = modelLeft; i<=modelLeft+3;++i){
			if(b[4 - (bottomLevel - j)][i- modelLeft +1] == 1){
				// printf("j = %d, i=%d\n",j,i );
				// printf("b[4 - (bottomLevel - j)][i- modelLeft +1] = %d\n",b[4 - (bottomLevel - j)][i- modelLeft +1]);
				a[j][i] = 1;
			}
		}
	}
}

void myprintf(int a[GraphDepth][GraphWidth]){
	for (int i = 1; i < 16; ++i)
	{
		for (int j = 1; j < 11; ++j)
		{
			printf("%d%c", a[i][j], j == 10 ? '\n' : ' ');
		}
	}
}

int main(){
	int a[GraphDepth][GraphWidth];
	rp(i,GraphDepth) rp(j,GraphWidth) a[i][j] = 1;
	// for (int i = 0; i < GraphDepth; ++i)
	// {
	// 	for (int j = 0; j < GraphWidth; ++j)
	// 	{
	// 		printf("%d ", a[i][j]);
	// 	}
	// 	printf("\n");
	// }
	for (int i = 1; i <= 15; ++i)
	{
		for (int j = 1; j <= 10; ++j)
		{
			scanf("%d", &a[i][j]);
		}
	}
	int b[5][5];
	for (int i = 1; i <= 4; ++i)
	{
		for (int j = 1; j <= 4; ++j)
		{
			scanf("%d", &b[i][j]);
		}
	}
	int left;scanf("%d", &left);
	merge(a,b,left);
	myprintf(a);
	
	return 0;
}